const {
  Msg,
} = require("../lib/consts");
const {
  welfare,    //福利时刻用户抽奖
  indexOilPump,   //点击首页油泵
  getPrize,   //点击获取奖品
} = require("../lib/action");

module.exports = function (app) { return new Handler(app); };
var Handler = function (app) { this.app = app; };
var handler = Handler.prototype;

//点击首页油泵
handler.indexOilPump = async function (msg, session, next) {
  try{
    throw new Error("此功能正在优化中...");
    let result = await indexOilPump.call(this, session);
    next(null, { code: 200, msg: Msg.RESULT_SUCCESS, data: result });
  }catch(err){
    next(err, {code: 500, msg: err.message});
  }
}

// 福利时刻用户抽奖
handler.welfare = async function (msg, session, next) {
  try{
    let prizeList = await welfare.call(this, session);
    next(null, { code: 200, msg: Msg.RESULT_SUCCESS, data: prizeList });
  }catch(err){
    next(err, {code: 500, msg: err.message});
  }
}

// 点击获取奖品
handler.getPrize = async function (msg, session, next) {
  try{
    await getPrize.call(this, session, msg);
    next(null, { code: 200, msg: Msg.RESULT_SUCCESS });
  }catch(err){
    next(err, {code: 500, msg: err.message});
  }
}

